﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InSys.Documents;

namespace InSys
{
    public partial class FormStart : Form
    {
        private FormDocument formDocument = null;


        public FormStart()
        {
            InitializeComponent();
            Init();
        }

        private void Init()
        {
            System.Windows.Forms.DialogResult dlgResult;
            if (Properties.Settings.Default.ShowSplashString)
            {
                SplashScreen frmSplash = new SplashScreen();
                frmSplash.ShowDialog();
            }
            FormLogin frmLogin = new FormLogin();
            while (true)
            {
                dlgResult = frmLogin.ShowDialog();
                if (dlgResult == System.Windows.Forms.DialogResult.OK)
                {
                    Program.login = true;
                    Program.id_department = frmLogin.IdDepartment;
                    Program.id_user = frmLogin.IdUser;
                    break;
                }
                if (dlgResult == System.Windows.Forms.DialogResult.Abort)
                {
                    MessageBox.Show(Properties.Resources.WrongUser);
                }
                if (dlgResult == System.Windows.Forms.DialogResult.Cancel)
                {
                    Program.login = false;
                    Program.id_department = 0;
                    Program.id_user = 0;
                    break;
                }
            }
        }

        private void toolStripButtonDocuments_Click(object sender, EventArgs e)
        {
            if (null == formDocument)
            {
                formDocument = new FormDocument(Program.id_user, Program.id_department);
                formDocument.Disposed += new EventHandler(formDocument_Disposed);
                formDocument.MdiParent = this;
                formDocument.Size = formDocument.MaximumSize;
                formDocument.Show();
            }
            formDocument.Activate();
        }

        void formDocument_Disposed(object sender, EventArgs e)
        {
            formDocument = null;
        }

        private void FormStart_Load(object sender, EventArgs e)
        {
            if (Program.login == false)
                Application.Exit();
        }
    }
}
